<template>
	<view class="reportWrap" :style="{marginTop:$u.addUnit(44 + $u.sys().statusBarHeight,'px'),}">
		<u-navbar :fixed="true" :title="titleName" :autoBack="true" :safeAreaInsetTop="true" leftIconColor="#fff">
			<view class="u-nav-slot x-ec" slot="right">
				<view v-if="$store.state.systemConfig.sysDeviceInfo.osName != 'ios'" style="margin-right: 10rpx;color: #fff;"
					@click="revolveBtn">旋转</view>

				<view @click="openSearch" style="width: 25px;height: 25px;">
					<uni-icons type="search" size="24" color="#fff"></uni-icons>
				</view>
			</view>
		</u-navbar>

		<!-- 表格 -->
		<view :style="{height:`${tableHeight}px`}">
			<zb-table ref="zbTable" @sort-change="sortChange" :pullUpLoading="pullUpLoading" :isShowLoadMore="true"
				:stripe="true" :show-summary="showSummary" :summary-method="getSummaries" :highlight="true"
				:show-header="true" :columns="column" :fit="false" :permissionBtn="permissionBtn" @rowClick="rowClick"
				@cellClick="cellClick" :border="true" :cell-style="cellStyle" @custom="custom" @edit="buttonEdit"
				@dele="dele" :data="data"></zb-table>
		</view>

		<!-- 搜索弹窗 -->
		<uni-popup ref="popup" type="bottom" background-color="#ffffff">
			<view class="popSearch">
				<view v-for="(row,index) in searchList" v-if="row.baseProperty.labelName">
					<view v-if="row.baseProperty.controlType == 'datepicker'" class="searchRow"
						@click="openDate(row,index)">
						<view class="rowRequire">
							<text v-show="row.baseProperty.isRequired">*</text>
						</view>
						<text class="rowLabel">{{row.baseProperty.labelName}}</text>
						<view class="rowValue">
							{{row.baseProperty.showValue.split(' ')[0]}}
						</view>
						<uni-icons type="right"></uni-icons>
					</view>
					<view v-if="row.baseProperty.controlType == 'textbox'" class="searchRow">
						<view class="rowRequire">
							<text v-show="row.baseProperty.isRequired">*</text>
						</view>
						<text class="rowLabel">{{row.baseProperty.labelName}}</text>
						<input class="rowValue" v-model="formData[row.baseProperty.controlName]"
							:placeholder="'请输入'+row.baseProperty.labelName"
							placeholder-style="font-size:13px;color:#999999;" style="border: none;"></input>
					</view>
					<view v-if="row.baseProperty.controlType == 'select' && row.controlProperty.select.type == 1"
						class="searchRow" @click="openSelect(row,index)">
						<view class="rowRequire">
							<text v-show="row.baseProperty.isRequired">*</text>
						</view>
						<text class="rowLabel">{{row.baseProperty.labelName}}</text>
						<view class="rowValue">
							{{row.baseProperty.showValue}}
						</view>
						<uni-icons type="right"></uni-icons>
					</view>
				</view>

				<button type="primary" size="mini" @click="searchReport">查询</button>
			</view>
		</uni-popup>

		<!-- 下拉选择弹窗 -->
		<uni-popup ref="popupSelect" type="bottom" background-color="#ffffff">
			<view class="picker-opt">
				<text @click="cancelSelect">取消</text>
				<text @click="confirmSelect">确认</text>
			</view>
			<picker-view :indicator-style="indicatorStyle" :value="value" class="picker-view" @change="changeSelect">
				<picker-view-column>
					<view class="item" v-for="(item,index) in selectColumns" :key="index">{{item[selectValueKey]}}
					</view>
				</picker-view-column>
			</picker-view>
		</uni-popup>

		<!-- 日期选择弹窗 -->
		<uni-popup ref="popupDate" type="bottom" background-color="#ffffff">
			<view class="picker-opt">
				<text @click="cancelDate">取消</text>
				<text @click="confirmDate">确认</text>
			</view>
			<picker-view :indicator-style="indicatorStyle" :value="value" class="picker-view" @change="changeDate">
				<picker-view-column>
					<view class="item" v-for="(item,index) in years" :key="index">{{item}}年</view>
				</picker-view-column>
				<picker-view-column>
					<view class="item" v-for="(item,index) in months" :key="index">{{item}}月</view>
				</picker-view-column>
				<picker-view-column>
					<view class="item" v-for="(item,index) in days" :key="index">{{item}}日</view>
				</picker-view-column>
			</picker-view>
		</uni-popup>
	</view>
</template>

<script>
	var editIndex = '';

	export default {
		data() {
			const date = new Date()
			const years = []
			const year = date.getFullYear()
			const months = []
			const month = date.getMonth() + 1
			const days = []
			const day = date.getDate()
			for (let i = 1990; i <= date.getFullYear(); i++) {
				years.push(i)
			}
			for (let i = 1; i <= 12; i++) {
				months.push(i)
			}
			for (let i = 1; i <= 31; i++) {
				days.push(i)
			}

			return {
				showSummary: false,
				tableHeight: 0, // 表格高度
				years,
				year,
				year2: '',
				months,
				month,
				month2: '',
				days,
				day,
				day2: '',
				value: [9999, month - 1, day - 1],
				indicatorStyle: `height: 40px;`,
				value: [],
				value2: [],

				column: [],
				data: [],
				flag1: true,
				flag2: true,

				titleName: '',
				// subTitleName: '',
				sql: '',
				rowClassCol: '',
				colClassCol: '',
				searchCallBack: '',
				spanMethodFunc: '',
				childFormList: [],
				formData: {},
				searchList: [],
				rowKey: 0,
				column_originConfig: [],
				column_config: [],

				linkColumn: [],

				selectValueKey: '',
				selectRealKey: '',
				selectColumns: [],
				pageRevolve: false, // 判断是否旋转, true-横屏；false-竖屏
			}
		},

		created() {
			let that = this;
			let menu = that.$store.state.Menu;
			that.initConfig(menu.Para);
			// 动态计算表格高度
			// uni.getSystemInfo({
			// 	success(info) {
			// 		// console.log(info);
			// 		that.tableHeight = info.windowHeight - info.safeAreaInsets.top - 44 - info.safeAreaInsets
			// 			.bottom;
			// 	}
			// })
		},
		mounted() {
			let that = this;

			that.getTableHeight();
		},

		onUnload() {
			plus.screen.lockOrientation('portrait'); // 切换到竖屏  
		},
		methods: {
			revolveBtn() { // 旋转按钮
				let that = this;
				let type = this.pageRevolve;

				if (type) {
					// 当前为横屏
					plus.screen.lockOrientation('portrait'); // 切换到竖屏  
				} else {
					// 当前为竖屏
					plus.screen.lockOrientation('landscape'); // 切换到横屏
				}
				this.pageRevolve = !type;
				setTimeout(() => {
					that.getTableHeight();
				}, 1000)
			},
			getTableHeight() { // 获取表格高度
				let that = this;
				uni.getSystemInfo({
					success(info) {
						// console.log(info);
						that.tableHeight = info.windowHeight - info.safeAreaInsets.top - 44 - info.safeAreaInsets
							.bottom;
					}
				})
			},

			// 打开搜索弹窗
			openSearch() {
				this.$refs.popup.open();
			},

			// 关闭搜索弹窗
			closeSearch() {
				this.$refs.popup.close();
			},

			// 打开日期选择
			openDate(row, index) {
				editIndex = index;
				this.$refs.popupDate.open();
				this.value = this.getCurrentDateIndex();
			},

			// 变更日期
			changeDate(e) {
				const val = e.detail.value
				this.year2 = this.years[val[0]];
				this.month2 = this.months[val[1]] > 9 ? this.months[val[1]] : '0' + this.months[val[1]];
				this.day2 = this.days[val[2]] > 9 ? this.days[val[2]] : '0' + this.days[val[2]];
				this.value2 = val;
			},

			// 确认日期选择
			confirmDate() {
				this.year = this.year2;
				this.month = this.month2;
				this.day = this.day2;
				this.value = this.value2;
				let currentDate = this.year + '-' + this.month + '-' + this.day; // 当前选中日期
				this.searchList[editIndex].baseProperty.showValue = currentDate;
				this.searchList[editIndex].baseProperty.value = currentDate;
				this.formData[this.searchList[editIndex].baseProperty.controlName] = currentDate;
				this.$refs.popupDate.close();
			},

			// 取消日期选择
			cancelDate() {
				this.$refs.popupDate.close();
			},

			// 打开选择
			openSelect(row, index) {
				var that = this;
				if (row.baseProperty.isReadOnly) return;

				if (editIndex != index || !this.selectColumns.length) {
					editIndex = index;
					var sql = "select * from (" + row.controlProperty.select.dataSource + ")t";
					var filter = row.controlProperty.select.formSQL + '';

					if (filter) {
						for (var key in that.formData) {
							var value = "'" + that.formData[key] + "'";
							var filterEvent = new Function("filter.replace(/" + "@" + key + "/g,value)");
							filterEvent();
						}
						sql += filter ? (' where ' + filter) : '';
					}

					// console.log(row.controlProperty.select.type)
					if (row.controlProperty.select.type == 1) {
						that.selectColumns = [];
						that.selectValueKey = row.controlProperty.select.displayValue;
						that.selectRealKey = row.controlProperty.select.hiddenValue;

						// console.log(that.selectValueKey)

						that.Request.requestByUrl('', {
								sql: sql
							},
							function(data) {
								// console.log(data)
								that.selectColumns = data.ds;
								that.$refs.popupSelect.open();
								// console.log(that.selectColumns);
							},
							function(err) {
								console.log(JSON.stringify(err));
							},
							that.Request.IPAgreement() + that
							.Request.serverIP() + '/SQLData/GetDataBySql');
					}
				} else {
					that.$refs.popupSelect.open();
				}
				that.getCurrentIndex();
			},

			// 切换选择
			changeSelect(e) {
				this.value2 = e.detail.value; // 更改选中索引
			},

			// 确认选择
			confirmSelect() {
				this.value = this.value2;
				let selectedColumn = this.selectColumns[this.value];
				this.searchList[editIndex].baseProperty.value = selectedColumn[this.selectRealKey];
				this.searchList[editIndex].baseProperty.showValue = selectedColumn[this.selectValueKey];
				this.formData[this.searchList[editIndex].baseProperty.controlName] = selectedColumn[this.selectRealKey];
				this.$refs.popupSelect.close();
			},

			// 取消选择
			cancelSelect() {
				this.$refs.popupSelect.close();
			},

			// 获取当前选中下标
			getCurrentIndex() {
				let index = -1;
				let value = this.searchList[editIndex].baseProperty.value ? this.searchList[editIndex].baseProperty.value :
					this.searchList[editIndex].baseProperty.defaultValue;
				index = this.selectColumns.findIndex(item => item[this.selectRealKey] == value);
				this.value = [index];
				this.value2 = this.value;
				// return index;
			},

			// 获取当前日期下表
			getCurrentDateIndex() {
				let value = [];
				let currentDage = this.searchList[editIndex].baseProperty.showValue;
				let initDate = '';
				if (currentDage.split(' ').length > 1) {
					initDate = currentDage.split(' ')[0];
				} else {
					initDate = currentDage;
				}
				let [year, month, day] = initDate.split('-').map(item => parseInt(item));
				// console.log(year, month, day);
				let yearIdx = this.years.findIndex(item => item == year);
				let monthIdx = this.months.findIndex(item => item == month);
				let dayIdx = this.days.findIndex(item => item == day);
				value = [yearIdx, monthIdx, dayIdx];

				this.year = this.years[value[0]];
				this.year2 = this.year;
				this.month = this.months[value[1]] > 9 ? this.months[value[1]] : '0' + this.months[value[1]];
				this.month2 = this.month;
				this.day = this.days[value[2]] > 9 ? this.days[value[2]] : '0' + this.days[value[2]];
				this.day2 = this.day;
				return value;
			},

			formatter(row, column, rowIndex, columnIndex) {

				return row.age + '岁'
			},

			// 表格排序
			sortChange(item, sorterMode, index) {

				console.log('触发排序', item, sorterMode, index)
			},

			// 单元格样式设置
			cellStyle({
				row,
				column,
				rowIndex,
				columnIndex
			}) {
				if (this.column[columnIndex].url) {
					return {
						color: '#071e5f',
						textDecoration: 'underline'
					}
				}
			},

			// 上拉加载
			pullUpLoading(done) {
				done('ok')
				// if (!this.flag1) {
				// 	return
				// }
				// setTimeout(() => {
				// 	this.data.push({
				// 		date: '2011-05-02',
				// 		name: '王小虎23',
				// 		province: '上海',
				// 		sex: 1,
				// 		price: 33,
				// 		id: 11111 + this.num,
				// 		age: '30',
				// 		city: '普陀区',
				// 		address: '上海市普',
				// 		zip: 200333
				// 	})

				// 	this.num++
				// 	if (this.num === 3) {
				// 		done('ok')
				// 		this.flag1 = false
				// 	} else {
				// 		done()
				// 	}
				// }, 2000)
			},

			permissionBtn(row, renders, rowIndex) {
				if (row.id == 2) {
					let arr = renders.filter(item => item.func === 'edit')
					return arr
				}
				return renders
			},

			pullUpLoadingAction(done) {
				// if (!this.flag2) {
				// 	return
				// }
				// setTimeout(() => {
				// 		this.data.push({
				// 			date: '2011-05-02',
				// 			name: '王小虎23',
				// 			province: '上海',
				// 			sex: 1,
				// 			price: 33,
				// 			id: "11111",
				// 			age: '30',
				// 			city: '普陀区',
				// 			address: '上海市普',
				// 			zip: 200333
				// 		})

				// 	this.num1++
				// 	if (this.num1 === 3) {
				// 		this.$refs.zbTable.pullUpCompleteLoading('ok')
				// 		this.flag2 = false
				// 	} else {
				// 		this.$refs.zbTable.pullUpCompleteLoading()
				// 	}
				// }, 1000)
			},

			// 编辑行
			buttonEdit(ite, index) {
				uni.showToast({
					icon: 'none',
					duration: 3000,
					title: '点击编辑'
				})
				console.log(ite, index)
			},

			// 删除行
			dele(ite, index) {
				uni.showToast({
					icon: 'none',
					duration: 3000,
					title: '点击删除'
				})
				// alert('点击删除')
				console.log(ite, index)
			},

			// 自定义
			custom() {
				uni.showToast({
					icon: 'none',
					duration: 3000,
					title: '点击自定义'
				})
			},

			currentChange(row, index) {
				uni.showToast({
					icon: 'none',
					duration: 3000,
					title: '选中当前一行'
				})
				console.log('单选', row, index)
			},

			// 行点击
			rowClick(row, index) {
				// uni.showToast({
				// 	icon: 'none',
				// 	duration: 3000,
				// 	title: '单击某行'
				// })
				// console.log('单击某行', row, index)
			},

			// 单元格点击
			cellClick(row, index, column) {
				console.log('点击单元格', row, index, column)

				if (row[column.name]) {
					uni.showToast({
						icon: 'none',
						duration: 3000,
						title: column.label + ':' + row[column.name]
					})
				}
			},

			// 获取合计
			getSummaries(param) {
				const {
					columns,
					data
				} = param;
				const sums = [];
				columns.forEach((column, index) => {
					if (index === 0) {
						sums[index] = '合计';
						return;
					}
					if (column.total && column.total.indexOf('sum') > -1) {
						const values = data.map(item => Number(item[column.name]));
						if (!values.every(value => isNaN(value))) {
							let ttt = values.reduce((prev, curr) => {
								const value = Number(curr);
								if (!isNaN(value)) {
									return prev + curr;
								} else {
									return prev;
								}
							}, 0);
							if (column.total.split(',').length > 1) {
								sums[index] = ttt.toFixed(parseInt(column.total.split(',')[
									1]));
							} else {
								sums[index] = ttt;
							}
						} else {
							sums[index] = 'N/A';
						}
					}
				});
				return sums;
			},

			// 验证必填项
			valitedRequired() {
				let that = this;
				var resultObj = {
					status: 200,
					msg: ""
				};

				for (var i = 0; i < that.searchList.length; i++) {
					if (that.searchList[i].baseProperty.isRequired && !that.formData[that.searchList[i].baseProperty
							.controlName]) {
						resultObj = {
							status: 500,
							icon: 'none',
							msg: that.searchList[i].baseProperty.labelName + "字段不能为空!"
						};
					}
				}
				return resultObj;
			},

			// 获取默认值
			getSYDefaultValue(funcName) {
				if (funcName.indexOf("getdate()") >= 0) {
					var date;
					if (funcName == "getdate()") {
						date = new Date();
					} else {
						date = new Date();
						Date.prototype.DateAdd = function(strInterval, Number) {
							var dtTmp = this;
							switch (strInterval) {
								case 's':
									return new Date(Date.parse(dtTmp) + (1000 * Number));
								case 'n':
									return new Date(Date.parse(dtTmp) + (60000 * Number));
								case 'h':
									return new Date(Date.parse(dtTmp) + (3600000 * Number));
								case 'd':
									return new Date(Date.parse(dtTmp) + (86400000 * Number));
								case 'w':
									return new Date(Date.parse(dtTmp) + ((86400000 * 7) * Number));
								case 'q':
									return new Date(dtTmp.getFullYear(), (dtTmp.getMonth()) + Number * 3, dtTmp
										.getDate(), dtTmp.getHours(), dtTmp.getMinutes(), dtTmp
										.getSeconds());
								case 'm':
									return new Date(dtTmp.getFullYear(), (dtTmp.getMonth()) + Number, dtTmp
										.getDate(),
										dtTmp.getHours(), dtTmp.getMinutes(), dtTmp.getSeconds());
								case 'y':
									return new Date((dtTmp.getFullYear() + Number), dtTmp.getMonth(), dtTmp
										.getDate(),
										dtTmp.getHours(), dtTmp.getMinutes(), dtTmp.getSeconds());
							}
						}
						var addFun = funcName.split('.')[1];
						eval("date=date." + addFun);
					}
					var seperator1 = "-";
					var seperator2 = ":";
					var month = date.getMonth() + 1 < 10 ? "0" + (date.getMonth() + 1) : date.getMonth() + 1;
					var strDate = date.getDate() < 10 ? "0" + date.getDate() : date.getDate();
					var currentdate = date.getFullYear() + seperator1 + month + seperator1 + strDate +
						" " + date.getHours() + seperator2 + date.getMinutes() +
						seperator2 + date.getSeconds();
					return currentdate;
				} else {
					if (typeof funcName == 'function') {
						return eval(funcName);
					} else {
						return funcName
					}
				}
			},

			// 报表查询
			searchReport() {
				let that = this;
				//验证必填项
				var valitedResult = that.valitedRequired();
				console.log(valitedResult);
				if (valitedResult.status == 500) {
					uni.showToast({
						title: valitedResult.msg
					})
					return;
				} else {
					that.closeSearch();
					var searchParam = [];
					// console.log(that.formData);
					for (var key in that.formData) {
						var formValue = that.formData[key];
						if (!formValue) {
							formValue = "";
						}
						if (typeof formValue == "object" && formValue.constructor == Array) {
							formValue = formValue.join(',');
						}
						searchParam.push({
							Key: key,
							Value: formValue
						})
					}

					// 上个页面查询参数暂时去掉
					// for (var key in api.pageParam) {
					// 	var formValue = api.pageParam[key];
					// 	if (!formValue) {
					// 		formValue = "";
					// 	}
					// 	if (typeof formValue == "object" && formValue.constructor == Array) {
					// 		formValue = formValue.join(',');
					// 	}
					// 	searchParam.push({
					// 		Key: key,
					// 		Value: formValue
					// 	})
					// }

					// console.log(searchParam)
					// console.log(that.sql);
					uni.showLoading({
						title: '加载中'
					})
					that.Request.requestByUrl('', {
							sql: that.sql,
							sqlParamStr: JSON.stringify(searchParam)
						},
						function(data) {
							// console.log(JSON.stringify(data));
							// 报表标题/副标题
							if (data.ds.length) {
								that.titleName = data.ds[0].title;
								// that.subTitleName = data.ds[0].subtitle;
								if (data.ds[0].treereport == 1) {
									that.rowKey = data.ds[0].mainKey;
								}
							}

							// 标题列配置
							if (data.ds1.length) {
								that.column_originConfig = data.ds1;
								that.column_config = data.ds1.filter(item => item.parentName == "");

								if (that.column_config.length) {
									that.column.push({
										type: 'index',
										label: '序号',
										width: 60,
										fixed: true
									});
								}
								for (var i = 0; i < that.column_config.length; i++) {
									let column = that.column_config[i];
									if (that.column_config[i].total != "") {
										that.showSummary = true;
									}
									that.column.push({
										name: column.name,
										label: column.label,
										width: column.width,
										fixed: column.isFrozen == 0 ? false : true,
										sorter: true,
										url: column.url,
										total: column.total,
										emptyString: ' '
									});
									// that.column_config[i].subColumn = that.getSubColumn(data.ds1, that
									// 	.column_config[i].name);
								}
								// console.log(that.column);
							}

							// 数据源配置
							if (data.ds2.length) {
								if (!that.rowKey) {
									console.log(data);
									that.data = data.ds2;
								} else {

								}
							} else {
								that.data = [];
							}


							// if (data.status == 200) {

							// 	//列配置
							// 	if (data.data.ds1 != undefined && data.data.ds1.length > 0) {
							// 		// let isUpdateShowColumns = true;
							// 		// if (vm.showColumns.length > 0) {
							// 		//     isUpdateShowColumns = false;
							// 		// }
							// 		vm.column_originConfig = data.data.ds1;
							// 		vm.column_config = JSLINQ(data.data.ds1).where(function(item) {
							// 			return item.parentName == ""
							// 		}).ToArray();

							// 		for (var i = 0; i < vm.column_config.length; i++) {
							// 			// if (isUpdateShowColumns) {
							// 			//     vm.showColumns.push(vm.column_config[i].name);
							// 			// }
							// 			if (vm.column_config[i].total != "") {
							// 				vm.showSummary = true;
							// 			}
							// 			vm.column_config[i].subColumn = vm.getSubColumn(data.data.ds1, vm
							// 				.column_config[i].name);
							// 			// for (var j = 0; j < vm.column_config[i].subColumn.length; j++) {
							// 			//     if (isUpdateShowColumns) {
							// 			//         vm.showColumns.push(vm.column_config[i].subColumn[j].name);
							// 			//     }
							// 			// }
							// 		}
							// 		// vm.$nextTick(function() {
							// 		//     vm.tableHeight = 500; //document.getElementsByClassName("report-table")[0].offsetHeight;
							// 		// })

							// 	}
							// 	//合计行数据
							// 	if (data.data.ds3 != undefined && data.data.ds3.length > 0) {
							// 		vm.summaryColumnData = data.data.ds3;
							// 	}
							// 	//数据源配置
							// 	if (data.data.ds2 != undefined && data.data.ds2.length > 0) {
							// 		//console.log(JSON.stringify(data.data.ds2))
							// 		if (!vm.rowKey) {
							// 			vm.tableData = data.data.ds2;
							// 		} else {
							// 			vm.tableData = JSLINQ(data.data.ds2).where(function(item) {
							// 				return item[data.data.ds[0].subKey].toString() == "0"
							// 			}).ToArray();
							// 			for (var i = 0; i < vm.tableData.length; i++) {
							// 				let children = JSLINQ(data.data.ds2).where(function(item) {
							// 					return vm.tableData[i][data.data.ds[0].mainKey] ==
							// 						item[data.data.ds[0].subKey]
							// 				}).ToArray();
							// 				if (children.length > 0) {
							// 					//vm.$set(vm.tableData[i], "hasChildren", true);
							// 					vm.setLeafNode(children, data.data.ds2, data.data.ds[0]
							// 						.mainKey, data.data.ds[0].subKey);
							// 					vm.$set(vm.tableData[i], "children", children);
							// 				}
							// 			}
							// 		}
							// 		var colProperty = {
							// 			columns: []
							// 		};
							// 		if (data.data.ds2.length > 0) {
							// 			var repeatColumn = function(array) {
							// 				for (var i in array) {
							// 					if (array[i].subColumn.length) {
							// 						repeatColumn(array[i].subColumn)
							// 					} else {
							// 						colProperty.columns.push({
							// 							property: array[i].name
							// 						});
							// 					}
							// 				}
							// 			}
							// 			repeatColumn(vm.column_config)

							// 			vm.summaryData = vm.getSummaries(colProperty);
							// 			var subTotalObj = JSLINQ(vm.column_config).where(function(item) {
							// 				return item.isSubTotal == 1
							// 			}).ToArray();
							// 			if (subTotalObj.length > 0) {
							// 				vm.subColTotal = subTotalObj[0].name;
							// 				vm.subSummaryData = vm.getSubSummaries(colProperty);
							// 			}


							// 			vm.$nextTick(function() {
							// 				setTimeout(function() {
							// 					$('#summaryFoot').width($(
							// 							'.el-table__body tbody tr')
							// 						.width() + 'px')
							// 					for (var i in vm.summaryData) {
							// 						$('#summaryFoot th').eq(i).find('div')
							// 							.width($('.el-table__body tbody tr td')
							// 								.eq(i).width() + 'px');
							// 					}
							// 				}, 300);

							// 				//vm.tableHeight = 500; //document.getElementsByClassName("report-table")[0].offsetHeight;
							// 				//vm.tableHeight = window.innerHeight - $('#reporthead').height() - $('#summaryData').height() - 32;
							// 			})
							// 		}
							// 		JSON.stringify(vm.tableData)
							// 	} else {
							// 		vm.tableData = [];
							// 	}
							// 	if (vm.searchCallBack) {
							// 		eval(vm.searchCallBack);
							// 	}
							// }
							// vm.closeLoading();
							uni.hideLoading();
						},
						function(err) {
							console.log(JSON.stringify(err));
						},
						that.Request.IPAgreement() + that
						.Request.serverIP() + '/SQLData/GetDataBySql_Uniapp');
				}
			},

			// 设置报表配置
			setConfig(options) {
				let that = this;
				that.sql = options.sql;
				that.rowClassCol = options.rowClassCol;
				that.colClassCol = options.colClassCol;
				that.searchCallBack = options.searchCallBack;
				that.spanMethodFunc = options.spanMethod;

				// if (options.chartConfig) {
				// 	that.chartConfig = JSON.parse(options.chartConfig);
				// 	that.initChart();
				// }

				// if (that.spanMethodFunc) {
				// 	$.appendNum = 500;
				// } else {
				// 	$.appendNum = 15;
				// }

				// vm.openLoading();
				if (options.childFormList == null) {
					options.childFormList = [];
				}
				that.childFormList = options.childFormList;

				var searchList = options.formDesign;
				console.log(searchList);
				var x = 0;
				for (var i in searchList) {
					searchList[i].baseProperty.value = '';
					searchList[i].baseProperty.showValue = '';
					that.formData[searchList[i].baseProperty.controlName] = '';
					console.log(searchList[i].baseProperty.defaultValue)
					if (searchList[i].baseProperty.defaultValue) {
						searchList[i].baseProperty.value = that.getSYDefaultValue(searchList[i].baseProperty
							.defaultValue);
						searchList[i].baseProperty.showValue = that.getSYDefaultValue(searchList[i].baseProperty
							.defaultValue);
						that.formData[searchList[i].baseProperty.controlName] = that.getSYDefaultValue(searchList[
								i]
							.baseProperty.defaultValue);
					}

					if (searchList[i].baseProperty.isRequired) {
						x = 1;
					}
				}
				that.searchList = searchList;
				console.log(that.searchList);

				//子报表自动查询
				//验证必填项
				var valitedResult = that.valitedRequired();
				console.log(valitedResult);
				var isSuccess = false;
				if (valitedResult.status == 200) {
					isSuccess = true;
				}

				that.$nextTick(() => {
					if (isSuccess) {
						// vm.openLoading();
						that.searchReport();
					}
				})
			},

			// 初始化报表配置
			initConfig(objName) {
				let that = this;
				if (objName == undefined) {
					return;
				}
				// console.log(objName);
				that.Request.request('', {
						objName: objName
					}, function(res) {
						console.log(res);
						if (res.status == 200) {
							var data = res;
							that.setConfig({
								sql: data.data.ds[0]["sql"],
								formDesign: JSON.parse(data.data.ds[0][
									"searchDesignConfig"
								]),
								rowClassCol: data.data.ds[0]["rowClassCol"],
								colClassCol: data.data.ds[0]["colClassCol"],
								searchCallBack: data.data.ds[0]["searchCallBack"],
								spanMethod: data.data.ds[0]["spanMethod"],
								chartConfig: data.data.ds[0]["chartConfig"]
							})
						}
					}, function(err) {
						console.log(JSON.stringify(err))
					}, that.Request.IPAgreement() + that
					.Request.serverIP() + '/ReportList/GetDataByName');
			}
		}
	}
</script>

<style scoped lang="scss">
	::v-deep {
		.uni-card {
			margin: 8px !important;
			padding: 0 !important;

			.uni-card__content {
				padding: 0 !important;
			}
		}
	}

	.reportWrap {
		display: flex;
		flex-direction: column;
	}

	// 选择弹窗
	.picker-opt {
		display: flex;
		justify-content: space-between;
		align-items: center;
		padding: 5px 10px;
		border-bottom: 1px solid #f2f2f2;
		font-size: 16px;
		height: 40px;
	}

	.picker-opt>text:first-child {
		color: #999999;
	}

	.picker-opt>text:last-child {
		color: #51d0d0;
	}

	.picker-view {
		width: 750rpx;
		height: 400rpx;
		margin-top: 20rpx;
	}

	.item {
		line-height: 40px;
		text-align: center;
	}

	// 搜索弹窗
	.popSearch {
		display: flex;
		flex-direction: column;
		padding: 10px;
		font-size: 14px;
		background-color: #fff;

		.searchRow {
			display: flex;
			align-items: center;
			padding: 5px;
			margin-bottom: 5px;

			.rowRequire {
				display: flex;
				justify-content: center;
				align-items: center;
				width: 8px;
				height: 8px;
				margin-right: 5px;

				text {
					color: red;
				}
			}

			.rowLabel {
				width: 72px;
				margin-right: 5px;
				color: #3a3a3a;
			}

			.rowValue {
				flex: 1;
				color: #999999;
			}

			.uni-icons {
				color: #999999 !important;
			}
		}

		button {
			background-color: #51d0d0;
			display: block;
			border-radius: 0;
		}
	}
</style>